clear all
set more off
set matsize 10000
tempfile ubigeo temp

/*

This dofile keeps the sample of individuals to be used. 

It drops individuals with missing observations in:

a. all trust variables
b. vote variable
c. birth and residence districts (since these variables are used for identification of exposure to conflict)
d. demographics: education and laguage

output: getsample.dta

*/


** PATHS
local working ../working

*** SELECTION
use `working'/trust, clear

** keep just years with voting data
keep if inlist(year,2007,2008,2009,2010,2011)

** merge identity (not used in regressions)
merge 1:1 year conglome vivienda hogar codperso using ../working/identity
drop if _merge == 2
drop _merge

** merge all other individual modules
merge 1:1 conglome vivienda hogar codperso year using `working'/participation
drop if _merge == 2
drop _merge

merge 1:1 conglome vivienda hogar codperso year using `working'/democracy
drop if _merge == 2
drop _merge

merge 1:1 conglome vivienda hogar codperso year using `working'/voting
drop if _merge == 2
drop _merge

merge 1:1 conglome vivienda hogar codperso year using `working'/300
drop if _merge == 2
drop _merge

merge 1:1 conglome vivienda hogar codperso year using `working'/200
drop if _merge == 2
drop _merge

** drop missings
egen nomiss = rownonmiss(trust_*)
drop if nomiss == 0
drop nomiss

drop if voted == .
drop if ubigeo1993 == .
drop if ubigeonac1993 == .
drop if educ_0 == .
drop if spanish == .

save `working'/getsample
